package com.bdit.ydcb.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bdit.ydcb.R;

/**
 * Created by shengpj on 2017/6/27.
 */

public class MainMenAdapter  extends BaseAdapter{
    private Context context;

    public MainMenAdapter(Context context) {
        this.context=context;
    }

    private Integer[] images = {
            //九宫格图片的设置
            R.drawable.cblr,
            R.drawable.icon_map,
            R.drawable.light_close,
            R.drawable.icon_5,
            R.drawable.icon_ycsb,
            R.drawable.icon_crash,
            R.drawable.icon_tj,
            R.drawable.icon_download,
            R.drawable.icon_gg
    };

    private String[] texts = {
            //九宫格图片下方文字的设置
            "抄表任务",
            "抄表导航",
            "手电筒",
            "附近表",
            "异常上报",
            "短信预约",
            "查询统计",
            "上传下载",
            "公告信息"
    };

    //get the number
    @Override
    public int getCount() {
        return images.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    //get the current selector's id number
    @Override
    public long getItemId(int position) {
        return position;
    }

    //create view method
    @Override
    public View getView(int position, View view, ViewGroup viewgroup) {
        ImgTextWrapper wrapper;
        if(view==null) {
            wrapper = new ImgTextWrapper();
            LayoutInflater inflater = LayoutInflater.from(context);
            view = inflater.inflate(R.layout.item_menu_main, null);
            view.setTag(wrapper);
            view.setPadding(15, 15, 15, 15);  //每格的间距
        } else {
            wrapper = (ImgTextWrapper)view.getTag();
        }

        wrapper.imageView = (ImageView)view.findViewById(R.id.MainActivityImage);
        wrapper.imageView.setBackgroundResource(images[position]);
        wrapper.textView = (TextView)view.findViewById(R.id.MainActivityText);
        wrapper.textView.setText(texts[position]);

        return view;
    }
}

class ImgTextWrapper {
    ImageView imageView;
    TextView textView;
}
